function getMissingNumber(arr) {
    const length = arr.length;
    let left = 0,
        right = length - 1;

    let res=-1

    while (left <= right) {
        const mid = (left + right) >> 1;
        if (arr[mid] != mid) {
            if (mid > 0 && arr[mid - 1] == mid - 1) {
                res=mid;
                break;
            }else{
                right=mid-1;
            }
        } else {
            if (mid < length - 1 && arr[mid + 1] != mid + 1) {
                res=mid + 1;
                break;
            }else{
                left=mid+1;
            }
        }
    }

    return res;
}

/* test */
arr = [0, 1, 2, 3, 5, 6, 7]; //缺5
console.log(getMissingNumber(arr));